package com.atguigu.lease.web.admin.service.impl;

import com.atguigu.lease.model.entity.ApartmentInfo;
import com.atguigu.lease.model.entity.LeaseAgreement;
import com.atguigu.lease.model.entity.RoomInfo;
import com.atguigu.lease.web.admin.mapper.ApartmentInfoMapper;
import com.atguigu.lease.web.admin.mapper.LeaseAgreementMapper;
import com.atguigu.lease.web.admin.mapper.RoomInfoMapper;
import com.atguigu.lease.web.admin.service.LeaseAgreementService;
import com.atguigu.lease.web.admin.vo.agreement.AgreementQueryVo;
import com.atguigu.lease.web.admin.vo.agreement.AgreementVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author liubo
 * @description 针对表【lease_agreement(租约信息表)】的数据库操作Service实现
 * @createDate 2023-07-24 15:48:00
 */
@Service
public class LeaseAgreementServiceImpl extends ServiceImpl<LeaseAgreementMapper, LeaseAgreement>
        implements LeaseAgreementService {

    @Autowired
    ApartmentInfoMapper apartmentInfoMapper;

    @Autowired
    RoomInfoMapper roomInfoMapper;

    @Override
    public IPage<AgreementVo> agreementVoIPage(IPage<AgreementVo> agreementVoIPage, AgreementQueryVo queryVo) {
        IPage<AgreementVo> agreementVoIPageReault = baseMapper.selectAgreementVoIPage(agreementVoIPage,queryVo);

        return agreementVoIPageReault;
    }

    @Override
    public AgreementVo getAgreementById(Long id) {
        //租赁信息
        LeaseAgreement leaseAgreement = baseMapper.selectById(id);

        //根据租赁信息获取公寓id和房间id
        Long apartmentId = leaseAgreement.getApartmentId();
        Long roomId = leaseAgreement.getRoomId();

        //获取房间信息和公寓信息
        ApartmentInfo apartmentInfo = apartmentInfoMapper.selectById(apartmentId);
        RoomInfo roomInfo = roomInfoMapper.selectById(roomId);

        AgreementVo agreementVo = new AgreementVo();
        agreementVo.setApartmentInfo(apartmentInfo);
        agreementVo.setRoomInfo(roomInfo);
        BeanUtils.copyProperties(leaseAgreement,agreementVo);  //又忘记做这一步了，要学会怎么测试、？？

        return agreementVo;
    }
}




